﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcAtletIS.Models;

namespace MvcAtletIS.Areas.Admin.Controllers
{
    [Authorize(Roles = "Administrators")]
    public class ClubsGroupsController : Controller
    {
        private atletisEntities db = new atletisEntities();

        // GET: /ClubsGroups/
        public ViewResult Index(string searchstring)
        {
            var clubsGroups = db.ClubsGroups.ToList();
            if (!string.IsNullOrEmpty(searchstring))
            {
                clubsGroups = clubsGroups.Where(cg => cg.Name.Contains(searchstring)).ToList();
            }
            return View(clubsGroups);
        }

        // GET: /ClubsGroups/Details/5
        public ViewResult Details(string id)
        {
            ClubsGroups clubsgroups = db.ClubsGroups.Single(c => c.ID == id);
            return View(clubsgroups);
        }

        // GET: /ClubsGroups/Create
        public ActionResult Create()
        {
            return View();
        } 

        // POST: /ClubsGroups/Create
        [HttpPost]
        public ActionResult Create(ClubsGroups clubsgroups)
        {
            clubsgroups.Modified = DateTime.Now;
            clubsgroups.Sync = true;
            
            if (ModelState.IsValid)
            {
                db.ClubsGroups.AddObject(clubsgroups);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(clubsgroups);
        }
        
        // GET: /ClubsGroups/Edit/5
        public ActionResult Edit(string id)
        {
            ClubsGroups clubsgroups = db.ClubsGroups.Single(c => c.ID == id);
            return View(clubsgroups);
        }

        // POST: /ClubsGroups/Edit/5
        [HttpPost]
        public ActionResult Edit(ClubsGroups clubsgroups)
        {
            clubsgroups.Modified = DateTime.Now;
            clubsgroups.Sync = true;
            
            if (ModelState.IsValid)
            {
                db.ClubsGroups.Attach(clubsgroups);
                db.ObjectStateManager.ChangeObjectState(clubsgroups, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(clubsgroups);
        }

        // GET: /ClubsGroups/Delete/5
        public ActionResult Delete(string id)
        {
            ClubsGroups clubsgroups = db.ClubsGroups.Single(c => c.ID == id);
            return View(clubsgroups);
        }

        // POST: /ClubsGroups/Delete/5
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {            
            ClubsGroups clubsgroups = db.ClubsGroups.Single(c => c.ID == id);
            db.ClubsGroups.DeleteObject(clubsgroups);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }




    }
}